﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class AutomaticallyArrangeContent : MonoBehaviour
{
    [Header("RectTransforms")]
    public RectTransform VideoAllContentTransform = null;

    public static event UnityAction UpdateContentPanelSize = null;

    private float videoAllContentSize = 126F;

    private void VideoAllContentPressed()
    {
        if (VideoAllContentTransform)
        {
            for (int i = 0; i < VideoAllContentTransform.childCount; i++)
            {
                videoAllContentSize += VideoAllContentTransform.GetChild(i).GetComponent<RectTransform>().sizeDelta.y;

                if (i == VideoAllContentTransform.childCount - 1)
                {
                    VideoAllContentTransform.sizeDelta = new Vector2(VideoAllContentTransform.sizeDelta.x, videoAllContentSize);
                }
            }
        }
    }

    public void InfoTextPressed(Text text)
    {
        RectTransform parent = text.GetComponentInParent<RectTransform>();
        parent.sizeDelta = new Vector2(text.text.Length * 42F + 65F, parent.sizeDelta.y);
    } 

    private void Update()
    {
        if (UpdateContentPanelSize != null)
        {
            VideoAllContentPressed();
            UpdateContentPanelSize = null;
        }
    }
}
